import pymysql

def areacup():
    config = {
        'host': "127.0.0.1"
        , 'port': 3306
        , 'user': 'root'
        , 'password': ''
        , 'db': 'test'
        , 'charset': 'utf8'
        , 'cursorclass': pymysql.cursors.DictCursor
    }
    connection = pymysql.connect(**config)
    try:
        with connection.cursor() as cursor:
            # 执行sql语句，插入记录
            sql = 'SELECT area,size from area_cup_clean'
            print(sql)
            cursor.execute(sql)
        # 没有设置默认自动提交，需要主动提交，以保存所执行的语句
        connection.commit()
        data = cursor.fetchall()
        return data
    except Exception as e:
        return 0
    finally:
        connection.close()


# [{'cup': 'B75', 'area': '广东', 'id': 1, 'size': 2}]
# [{'size': 2, 'area': '广东'}, {'size': 2, 'area': '福建'}]

if __name__ == '__main__':
    data ={}
    size = {"A":0,"B":0,"C":0,"D":0,"E":0,"F":0,"G":0}
    # print(areacup())
    area = [{'area': '广东'}, {'area': '福建'}, {'area': '北京'}, {'area': '云南'}, {'area': '江苏'}, {'area': '湖北'}, {'area': '河北'}, {'area': '天津'}, {'area': '四川'}, {'area': '广西'}, {'area': '山西'}, {'area': '贵州'}, {'area': '山东'}, {'area': '湖南'}, {'area': '上海'}, {'area': '辽宁'}, {'area': '陕西'}, {'area': '青海'}, {'area': '吉林'}, {'area': '安徽'}, {'area': '河南'}, {'area': '江西'}, {'area': '浙江'}, {'area': '宁夏'}, {'area': '甘肃'}, {'area': '黑龙江'}, {'area': '内蒙古'}, {'area': '新疆'}, {'area': '重庆'}, {'area': '西藏'}, {'area': '海南'}, {'area': '钓鱼岛'}, {'area': '台湾'}, {'area': '香港'}, {'area': '澳门'}]
    for i in area:
        data[i['area']] = size

    dbdata = areacup()

    print(dbdata)
    # print("------------------")
    # data['内蒙古'] = "是的撒多撒"
    # #print(data['内蒙古']['A'])
    # print(data["内蒙古"])


    for prama in dbdata:
        if prama['size'] ==1:
            tmp = data[prama['area']]
            tmp['A'] +=1
            data[prama['area']] = tmp
        if prama['size'] ==2:
            tmp = data[prama['area']]
            tmp['B'] += 1
            data[prama['area']] = tmp
        if prama['size'] ==3:
            tmp = data[prama['area']]
            tmp['C'] += 1
            data[prama['area']] = tmp
        if prama['size'] ==4:
            tmp = data[prama['area']]
            tmp['D'] += 1
            data[prama['area']] = tmp
        if prama['size'] ==5:
            tmp = data[prama['area']]
            tmp['E'] += 1
            data[prama['area']] = tmp
        if prama['size'] ==6:
            tmp = data[prama['area']]
            tmp['F'] += 1
            data[prama['area']] = tmp
        if prama['size'] ==7:
            tmp = data[prama['area']]
            tmp['G'] += 1
            data[prama['area']] = tmp


    for i in data.keys():
        print("{}:{}".format(i,data[i]))